#include <iostream>

/**
 * C++ 中指向类的指针  实例
 */
class Box {
private:
    double length;
    double breadth;
    double height;
public:
    Box(double l = 2.0,double b = 2.0,double h = 2.0){
        std::cout << "Constructor called." << std::endl;
        length = l;
        breadth = b;
        height = h;
    }

    double Volume(){
        return length * breadth * height;
    }
};

int main() {

    Box box1(3.3,1.2,1.5);
    Box box2(8.5,6.0,2.0);
    Box *ptrBox;

    //保存第一个对象的地址
    ptrBox = &box1;

    //现在尝试使用文成员访问运算符來访问成员
    std::cout << "Volume of Box1 : " << ptrBox->Volume() << std::endl;

    //保存第二个对象的地址
    ptrBox = &box2;

    //现在使用成员访问运算符來访问成员
    std::cout << "Volume of Box2 :" << ptrBox->Volume() << std::endl;

    return 0;
}
